var app = getApp(), fetchApi = require("../../../utils/httpPost.js")

function getUrl(e) {
  console.log('getUrl', e)
  var a = e.type;
  return "notice" === a ? notice(e) : "multitype" === a ? t(e) : "product" === a ? goodsDetail(e) 
    : "group" === a ? groupDetail(e) : 'active' === a ? goActiveDetail(e)
    : "goods" === a ? goodsDetail(e) : "page" === a ? goPage(e) : "shop" ===a ? shopDetail(e) : void 0;
}

function goLink(e) {
  console.log('golink e', e)

  var t = getUrl(e);
  console.log('getUrl',t)
  if (t) {
    getApp().goUrl(t);
  }
}


  /**
   * 获取页面数据的 http请求
   */
function onHttpBuy(skuId) {
    var that = this;
    fetchApi.httpPost('/product/order/addOrderBuyNow', {
      attr_value_id: skuId,
      count: 1,
      order_type: 0, //  积分商品订单
    }, function (res) {
      console.log("购买商品 ", res)
      if (res.data.code == 0) {
        var orderId = res.data.data;
        wx.redirectTo({
          url: '/pages/pay/paySubmit/index?order_id=' + orderId
        })
      } else if(res.data.code == 2){
        that.handleEstate();
      }
       else{
        console.log("购买商品 异常", res.data.msg)
        Toast.fail(res.data.msg)
      }
    }, function () {
      that.setData({ isLoading: false, loading: true, netWork: true, })
    })
}

function shopDetail(e) {
  console.log('店铺定位等 e', e)
  var item = e.data.item
  var latitude = item.latitude
  var longitude = item.longitude
  var url = '/pages/shop/detail/index?id=' + item.id
  return url;
}

function groupDetail(e){
  console.log('拼团详情 e', e)
  var item = e.data.item;
  var url = '';
  url = '/pages/product/group/index?id=' + item.linkId;
  return url;
}


function goActiveDetail(e){
  console.log('社区活动详情 e', e)
  var item = e.data.item;
  var url = '';
  url = '/pagesProperty/pages/active/detail/index?id=' + item.id;
  return url;
}

function notice(e) {
  console.log('通知公告 e',e)
  var a = e.data, t = a.type, i = a.item.linkKey, n = "", s = (e.saOption || {}).componentName,k = a.item.id;
  console.log('t ',t)
  if ("notice" == t) { n = '/pages/notice/detail/index?id=' + i }///文章
  else {
    if ("MINIPROGRAM_LINK" !== t) return "";
    n = i;
  }
  return s && (n += "&sa_unit=" + s), n;
}
function t(e) {
  console.log('砍价等 e',e);
  var a = e.data, t = a.type, i = a.item.linkId, n = "", s = (e.saOption || {}).componentName, k = a.item.id;
  console.log('t ',t);
  if ("article" == t) { n = '/pages/article/index?id=' + i }///文章
  else if ("page" === t) { n = "/pages/smallPage/index?id=" + i; } //商品页
  else if ("product" === t) { n = "/pages/product/detail/index?id=" + i;} //商品详情
  else if ("link" === t) n = i; 
  else {
    if ("MINIPROGRAM_LINK" !== t) return "";
    n = i;
  }
  return s && (n += "&sa_unit=" + s), n;
}
//商品
function goodsDetail(e) {
  console.log('商品 e', e);
  var linkType = e.data.item.linkType;
  console.log('linkType',linkType);
  var a = e.data.item, n="";
  console.log('a',a);
  if (linkType == 'group'){//团购的 商品详情
    var i = a.groupbuy.id;
    var c = a.groupbuy.linkType;// 1 - 商品  2 - 优惠券
    var linkId = a.groupbuy.linkId;
    n = "/pages/product/detail/index?id=" + linkId + "&group_id=" + i +"&groupopenId=0";
  } else if (linkType == 'product') {//普通商品的 商品详情
    n = a.linkUrl;
  } else if (linkType == 'coupon'){//优惠券的 商品详情
    n = "/pages/product/detail/index?id=" + linkId;
  } else {
    var linkId = a.id;
    n = "/pages/product/detail/index?id=" + linkId;
  }
  return n;
}
//商品页
function goPage(e) {
  console.log('商品页 e', e)
  var a = e.data.item.linkUrl, t = e.data.item.linkTitle;
  return t && (a += "&title=" + t), a;
}

Object.defineProperty(exports, "__esModule", {
  value: !0
});

var s = require("../../../utils/formatTime.js");

exports.default = {
  goLink: goLink,
  getMultitypeUrl: t
}, exports.goLink = goLink, exports.getMultitypeUrl = t;